<template>
	<view>
		<!-- 头部内容 -->
		<u-sticky>
			<view class="dingbu ffffff mainpadding" style="padding-top: 80rpx;">
				<view class="flexbetween">
					<view class="" @click="fanhsyy">
						<u-icon name="arrow-left" color="#000000" size="28"></u-icon>
					</view>
					<view class="flexbetween huibox">
						<view :class="currenttab==1?'yixz flexcenter':'weixianz flexcenter'" @click="selectab(1)">
							<view>租车</view>
						</view>
						<view :class="currenttab==2?'yixz flexcenter':'weixianz flexcenter'" @click="selectab(2)">
							<view>买车</view>
						</view>
						<view :class="currenttab==3?'yixz flexcenter':'weixianz flexcenter'" @click="selectab(3)">
							<view>住宿</view>
						</view>
						<view :class="currenttab==4?'yixz flexcenter':'weixianz flexcenter'" @click="selectab(4)">
							<view>餐饮</view>
						</view>
						<view :class="currenttab==5?'yixz flexcenter':'weixianz flexcenter'" @click="selectab(5)">
							<view>养护</view>
						</view>
					</view>
					<view class=""></view>
				</view>
				<u-tabs :list="list1" lineColor="#FF9341" @click="changetab" :scrollable="false" :activeStyle="{
					    color: '#000000',
					    fontWeight: 'bold',
					    transform: 'scale(1.05)'
					}" :inactiveStyle="{
					            color: '#666666',
								fontWeight: '500',
					            transform: 'scale(1)'
					        }" ></u-tabs>
			</view>
		</u-sticky>
		<!-- 商品 -->
		<view class="mainpadding2">
			<view class="flexcolumn" v-if="list.data.length==0">
				<view class="placeholderimage" style="margin-top: 100rpx;"></view>
				<view class="xiaohui margin_top main_size">暂无数据</view>
			</view>
			<!-- 租买车 -->
			<view class="" v-if="currenttab==1 || currenttab==2">
				<view class="ffffff radius margin_top mainpadding" v-for="item in list.data" :key="item.id" @click="tzddxq(1,item.id)">
					<view class="flexbetween">
						<view class="ershiba zhonghei fonweight">订单编号：{{item.order_no}}</view>
						<!-- 订单状态:1=待支付,2=待处理,3=已完成,4=已取消 -->
						<view class="strongtext fonweight xiaocheng " v-if="item.state==1">待支付</view>
						<view class="strongtext fonweight xiaocheng " v-if="item.state==2">待处理</view>
						<view class="strongtext fonweight xiaolv" v-if="item.state==3">已处理</view>
						<view class="strongtext fonweight xiaohui" v-if="item.state==4">已取消</view>
					</view>
					<view class="xiahuaxian">
						<view class="flextop margin_top">
							<image class="sptp" :src="item.car_image_text" mode=""></image>
							<view class="flexcolumnbet" style="width: 77%;height: 124rpx;">
								<view class="ershiba xiaohei yhxk">{{item.car_name}}</view>
								<view class="strongtext xiaohui">{{item.difference}}</view>
								<view class="flexbetween" style="width: 100%;">
									<view class="titletext xiaohong fonweight">¥{{item.pay_price}}</view>
									<view class="ershil xiaocheng">x1</view>
								</view>
							</view>
						</view>
					</view>
					<view class="flexright margin_top">
						<view class="qxbtn flexcenter" v-if="item.state==1" @click.stop="cancelItem(item.id,'/api/carordercl/cancelOrder')">取消订单</view>
						<view class="xhbtn flexcenter margin_left2" v-if="item.state==1" @click.stop="tzzf(1,item)">立即支付</view>
						<view class="qxbtn flexcenter" v-if="item.state==2">查看详情</view>
						<view class="xhbtn flexcenter" v-if="item.state==3 && item.comment_status==1" @click.stop="tzljpj(1,item.id)">立即评价</view>
						<view class="qxbtn flexcenter margin_left2" v-if="item.state==3 || item.state==4" @click.stop="delItem(item.id,'/api/carordercl/delOrder')">删除订单</view>
					</view>
				</view>
			</view>
			<!-- 住宿 -->
			<view class="" v-if="currenttab==3">
				<view class="ffffff radius margin_top mainpadding" v-for="item in list.data" :key="item.id" @click="tzddxq(2,item.id)">
					<view class="flexbetween">
						<view class="flexleft" @click.stop="jumpdetail('/pages_index/jiudianxq?id=',item.hotel.id)">
							<image class="margin_right1" style="width: 26.62rpx;height: 24rpx;" src="../static/images/system/fz.png" mode=""></image>
							<view class="ershiba zhonghei yhxk fonweight" style="max-width: 300rpx;">{{item.hotel.name}}</view>
							<u-icon name="arrow-right" color="#999999" ></u-icon>
						</view>
						<!-- 订单状态:订单状态:10=待支付,20=待处理,30=已完成-10=已取消 -->
						<view class="strongtext fonweight xiaocheng " v-if="item.order_status==10">待支付</view>
						<view class="strongtext fonweight xiaocheng " v-if="item.order_status==20">待处理</view>
						<view class="strongtext fonweight xiaolv" v-if="item.order_status==30">已处理</view>
						<view class="strongtext fonweight xiaohui" v-if="item.order_status==-10">已取消</view>
					</view>
					<view class="xiahuaxian">
						<view class="flextop margin_top">
							<image class="sptp" :src="item.hoteltype.image_text" mode=""></image>
							<view class="flexcolumnbet" style="width: 77%;height: 124rpx;">
								<view class="ershiba xiaohei yhxk">{{item.hoteltype.name}}</view>
								<view class="flexbetween" style="width: 100%;">
									<view class="titletext xiaohong fonweight">¥{{item.pay_price}}</view>
									<view class="ershil xiaocheng">x1</view>
								</view>
							</view>
						</view>
					</view>
					<!-- <view class="strongtext xiaohei margin_top textright">共计1件商品 合计
						<text class="xiaohong titletext nofonweight">￥98.00</text>
					</view> -->
					<view class="flexright margin_top">
						<view class="qxbtn flexcenter" v-if="item.order_status==10" @click.stop="cancelItem(item.id,'/api/Hotelordercl/cancelOrder')">取消订单</view>
						<view class="xhbtn flexcenter margin_left2" v-if="item.order_status==10" @click.stop="tzzf(2,item)">立即支付</view>
						<view class="qxbtn flexcenter" v-if="item.order_status==20">查看详情</view>
						<view class="xhbtn flexcenter" v-if="item.order_status==30 && item.comment_status==10" @click.stop="tzljpj(2,item.id)">立即评价</view>
						<view class="qxbtn flexcenter margin_left2" v-if="item.order_status==30 || item.order_status==-10" @click.stop="delItem(item.id,'/api/Hotelordercl/delOrder')">删除订单</view>
					</view>
				</view>
			</view>
			<!-- 餐饮 -->
			<view class="" v-if="currenttab==4">
				<view class="ffffff radius margin_top mainpadding" v-for="item in list.data" :key="item.id" @click="tzddxq(3,item.id)">
					<view class="flexbetween">
						<view class="flexleft" @click.stop="jumpdetail('/pages_index/canyinxq?id=',item.foodshop_id)">
							<image class="margin_right1" style="width: 26.62rpx;height: 24rpx;" src="../static/images/system/fz.png" mode=""></image>
							<view class="ershiba zhonghei yhxk fonweight" style="max-width: 300rpx;">{{item.foodshop.name}}</view>
							<u-icon name="arrow-right" color="#999999" ></u-icon>
						</view>
						<!-- 订单状态:1=待支付,2=待处理,3=已完成,4=已取消 -->
						<view class="strongtext fonweight xiaocheng " v-if="item.state==1">待支付</view>
						<view class="strongtext fonweight xiaocheng " v-if="item.state==2">待处理</view>
						<view class="strongtext fonweight xiaolv" v-if="item.state==3">已处理</view>
						<view class="strongtext fonweight xiaohui" v-if="item.state==4">已取消</view>
					</view>
					<view class="xiahuaxian">
						<view class="flextop margin_top " v-for="ite in item.goods" :key="ite.id">
							<image class="sptp" :src="ite.image_text" mode=""></image>
							<view class="flexcolumnbet" style="width: 77%;height: 124rpx;">
								<view class="ershiba xiaohei yhxk">{{ite.title}}</view>
								<view class="strongtext xiaohui">{{ite.difference}}</view>
								<view class="flexbetween" style="width: 100%;">
									<view class="titletext xiaohong fonweight">{{ite.price}}</view>
									<view class="ershil xiaocheng">x{{ite.number}}</view>
								</view>
							</view>
						</view>
					</view>
					<view class="strongtext xiaohei margin_top textright">共计1件商品 合计
						<text class="xiaohong titletext nofonweight">￥{{item.pay_price}}</text>
					</view>
					<view class="flexright margin_top">
						<view class="qxbtn flexcenter" v-if="item.state==1" @click.stop="cancelItem(item.id,'/api/Foodshoporder/cancelOrder')">取消订单</view>
						<view class="xhbtn flexcenter margin_left2" v-if="item.state==1" @click.stop="tzzf(4,item)">立即支付</view>
						<view class="qxbtn flexcenter" v-if="item.state==2">查看详情</view>
						<view class="xhbtn flexcenter" v-if="item.state==3 && item.comment_status==1" @click.stop="tzljpj(3,item.id)">立即评价</view>
						<view class="qxbtn flexcenter margin_left2" v-if="item.state==3 || item.state==4" @click.stop="delItem(item.id,'/api/Foodshoporder/delOrder')">删除订单</view>
					</view>
				</view>
			</view>
			<!-- 养护 -->
			<view class="" v-if="currenttab==5">
				<view class="ffffff radius margin_top mainpadding" v-for="item in list.data" :key="item.id" @click="tzddxq(4,item.id)">
					<view class="flexbetween">
						<view class="flexleft" @click.stop="jumpdetail('/pages_index/shangjiaxqchelwh?id=',item.carshop.id)">
							<image class="margin_right1" style="width: 26.62rpx;height: 24rpx;" src="../static/images/system/fz.png" mode=""></image>
							<view class="ershiba zhonghei yhxk fonweight" style="max-width: 300rpx;">{{item.carshop.name}}</view>
							<u-icon name="arrow-right" color="#999999" ></u-icon>
						</view>
						<!-- 订单状态:1=待支付,2=待处理,3=已完成,4=已取消 -->
						<view class="strongtext fonweight xiaocheng " v-if="item.state==1">待支付</view>
						<view class="strongtext fonweight xiaocheng " v-if="item.state==2">待处理</view>
						<view class="strongtext fonweight xiaolv" v-if="item.state==3">已处理</view>
						<view class="strongtext fonweight xiaohui" v-if="item.state==4">已取消</view>
					</view>
					<view class="xiahuaxian">
						<view class="flextop margin_top " >
							<image class="sptp" :src="item.carshop_goods_image_text" mode=""></image>
							<view class="flexcolumnbet" style="width: 77%;height: 124rpx;">
								<view class="ershiba xiaohei yhxk">{{item.carshop_goods_name}}</view>
								<view class="flexbetween" style="width: 100%;">
									<view class="titletext xiaohong fonweight">¥{{item.pay_price}}</view>
									<view class="ershil xiaocheng">x1</view>
								</view>
							</view>
						</view>
					</view>
					<view class="strongtext xiaohei margin_top textright">共计1件商品 合计
						<text class="xiaohong titletext nofonweight">￥{{item.pay_price}}</text>
					</view>
					<view class="flexright margin_top">
						<view class="qxbtn flexcenter" v-if="item.state==1" @click.stop="cancelItem(item.id,'/api/Carshopordercl/cancelOrder')">取消订单</view>
						<view class="xhbtn flexcenter margin_left2" v-if="item.state==1" @click.stop="tzzf(3,item)">立即支付</view>
						<view class="qxbtn flexcenter" v-if="item.state==2">查看详情</view>
						<view class="xhbtn flexcenter" v-if="item.state==3 && item.comment_status==1" @click.stop="tzljpj(4,item.id)">立即评价</view>
						<view class="qxbtn flexcenter margin_left2" v-if="item.state==3 || item.state==4" @click.stop="delItem(item.id,'/api/Carshopordercl/delOrder')">删除订单</view>
					</view>
				</view>
			</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				currenttab: 1,
				resultcode: 0,
				list1: [{
						name: '全部',
						value: 0,
					},
					{
						name: '待处理',
						value: 1,
					}, {
						name: '已处理',
						value: 2,
					}
				],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				modal:{
					modalShow:false,
					title:"",
				},
				currentapi:"",
				currentid:""
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			tzzf(val,item){
				let data = {
					order_id:item.id,
					pay_price:item.pay_price,
					pay_score:item.score,
					type:val
				}
				uni.navigateTo({
					url: '/pages_index/zhifuTwo?msg='+encodeURIComponent(JSON.stringify(data))
				})
			},
			cancelItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认取消订单？"
				this.modal.modalShow = true
			},
			delItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认删除当前订单？"
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认取消订单？"){
					this.cancelorder()
				}else if(this.modal.title=="是否确认删除当前订单？"){
					this.delOrder()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			cancelorder(){
				httpRequest.request(this.currentapi, 'GET', {
					order_id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			delOrder(){
				httpRequest.request(this.currentapi, 'POST', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			init(isPage, page) {
				let _this = this;
				let status = [
					{//租买车
						arr:[0,2,3]
					},
					{//住宿
						arr:[0,20,30]
					},
					{//餐饮
						arr:[0,2,3]
					},
					{//养护
						arr:[0,2,3]
					}
				]
				let currentindex = Number(this.currenttab)-1
				let apiList = [
					{//租车
						url:"/api/carordercl/getOrderList",
						data:{
							page: page || 1,
							limit: _this.limit,
							order_type:1,
							state:status[0].arr[this.resultcode]
						}
					},
					{//买车
						url:"/api/carordercl/getOrderList",
						data:{
							page: page || 1,
							limit: _this.limit,
							order_type:2,
							state:status[0].arr[this.resultcode]
						}
					},
					{//住宿
						url:"/api/hotelordercl/myOrder",
						data:{
							page: page || 1,
							limit: _this.limit,
							status:status[1].arr[this.resultcode]
						}
					},
					{//餐饮
						url:"/api/Foodshoporder/getOrderList",
						data:{
							page: page || 1,
							limit: _this.limit,
							state:status[2].arr[this.resultcode]
						}
					},
					{//养护
						url:"/api/Carshopordercl/getOrderList",
						data:{
							page: page || 1,
							limit: _this.limit,
							state:status[3].arr[this.resultcode]
						}
					},
				]
				httpRequest.request(apiList[currentindex].url, 'GET',apiList[currentindex].data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转订单详情
			tzddxq(type,id){
				uni.navigateTo({
					url:'/pages_mypage/quanbudingdxq?type='+type+"&id="+id
				})
			},
			// 返回上一页
			fanhsyy() {
				uni.navigateBack(1)
			},
			selectab(i) {
				if (i == this.currenttab) {
					return false
				}
				this.currenttab = i
				this.page = 1
				this.list = {
					data:[]
				}
				this.init()
			},
			// 跳转立即评价
			tzljpj(type,id){
				uni.navigateTo({
					url:'/pages_mypage/tiaozhuanlijipj?type='+type+"&id="+id
				})
			},
			changetab(e){
				if(e.value==this.resultcode){
					return false
				}
				this.resultcode = e.value
				this.page = 1
				this.list = {
					data:[]
				}
				this.init()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.xhbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF9341;
		border-radius: 120rpx;
		border: 2rpx solid #FF9341;
	}

	.qxbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #666666;
		border-radius: 120rpx;
		border: 2rpx solid #666666;
	}

	.sptp {
		width: 124rpx;
		height: 124rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}

	.huibox {
		padding: 6rpx;
		background: rgba(96, 96, 96, 0.1);
		border-radius: 116rpx 116rpx 116rpx 116rpx;
	}

	.weixianz {
		width: 117rpx;
		height: 74rpx;
		font-weight: 500;
		font-size: 26rpx;
		color: #666666;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.yixz {
		width: 117rpx;
		height: 74rpx;
		background: #FFFFFF;
		font-weight: 800;
		font-size: 26rpx;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 72rpx 72rpx 72rpx 72rpx;
	}
</style>